<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>基本资料</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__ADMIN_LAYUIMINI__/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="__ADMIN_LAYUIMINI__/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="__ADMIN_LAYUIMINI__/css/public.css" media="all">
    <style>
        .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form">
            
            <div class="layui-form-item">
                <label class="layui-form-label">父级权限</label>
                <div class="layui-input-block">
                    <input type="text" name="pid" value="0" id="treeSelect" lay-filter="treeSelect" class="layui-input">
                </div>
            </div>
            
            <div class="layui-form-item">
                <label class="layui-form-label required">权限名称</label>
                <div class="layui-input-block">
                    <input type="text" name="title" lay-verify="required" lay-reqtext="权限名称不能为空" placeholder="请输入权限名称" value="" class="layui-input">
                </div>
            </div>
            
            <div class="layui-form-item">
                <label class="layui-form-label required">图标选择</label>
                <div class="layui-input-block">
                    <input type="text" name="icon" id="iconPicker" lay-filter="iconPicker" class="hide">
                </div>
            </div>
            
            <div class="layui-form-item">
                <label class="layui-form-label">控制器</label>
                <div class="layui-input-block">
                    <input type="text" name="c" placeholder="请输入控制器" value="" class="layui-input">
                </div>
            </div>
            
            <div class="layui-form-item">
                <label class="layui-form-label">权限标识</label>
                <div class="layui-input-block">
                    <input type="text" name="a" placeholder="请输入权限标识" value="" class="layui-input">
                    <tip>英文唯一标识，等同方法名</tip>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">是否主菜单</label>
                <div class="layui-input-block">
                    <input type="checkbox" name= "type" lay-filter="switchtype" lay-skin="switch" lay-text="是|否">
                </div>
            </div>
            
            <div>{:token_field()}</div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="__ADMIN_LAYUIMINI__/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="__ADMIN_LAYUIMINI__/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="__ADMIN_LAYUIMINI__/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['iconPickerFa', 'form', 'miniTab', 'treeSelect'], function () {
        var form = layui.form,
            layer = layui.layer,
            iconPickerFa = layui.iconPickerFa,
            treeSelect = layui.treeSelect,
            miniTab = layui.miniTab;
            
        treeSelect.render({
            elem: '#treeSelect',
            data: "{:url('getTreeAuth')}",
            // 异步加载方式：get/post，默认get
            type: 'get',
            // 占位符
            placeholder: '请选择父级权限，不选则为顶级权限',
            search: true,
            style: {
                folder: {
                    enable: false
                },
                line: {
                    enable: true
                }
            },
            // 点击回调
            click: function(d){
                $('#treeSelect').attr('value', d.current.id)
                console.log(d);
            },
            // 加载完成后的回调函数
            success: function (d) {
//                选中节点，根据id筛选
//                treeSelect.checkNode('tree', 3);

//                获取zTree对象，可以调用zTree方法
//                var treeObj = treeSelect.zTree('tree');
//                console.log(treeObj);

//                刷新树结构
//                treeSelect.refresh('treeSelect');
            }

        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            data = data.field;
            url = "{:url('add')}";
            var indexLoad = layer.load(1, {shade: [0.1,'#fff']});
            $.ajax({
                url,
                data,
                type:"POST",
                success(res){
                    layer.close(indexLoad);
                    console.log(res);
                    layer.msg(res.message);
                    if (res.status == 1) {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        window.parent.location.reload();
                        parent.layer.close(index); //再执行关闭
                    }
                }
            })
            
            return false;
        });
        
        iconPickerFa.render({
            // 选择器，推荐使用input
            elem: '#iconPicker',
            // fa 图标接口
            url: "__ADMIN_LAYUIMINI__/lib/font-awesome-4.7.0/less/variables.less",
            // 是否开启搜索：true/false，默认true
            search: true,
            // 是否开启分页：true/false，默认true
            page: true,
            // 每页显示数量，默认12
            limit: 12,
            // 点击回调
            click: function (data) {
                console.log(data);
            },
            // 渲染成功后的回调
            success: function (d) {
                console.log(d);
            }
        });

    });
</script>
</body>
</html>